package com.itheima.server.controller;

import com.itheima.domain.vo.Answers;
import com.itheima.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 阿鹏
 * @date 2021/3/1 20:40
 */
@RestController
@RequestMapping("testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    // 问卷列表
    @GetMapping
    public ResponseEntity findQuestionsList() {
        return testSoulService.findQuestionsList();
    }

    // 提交问卷
    @PostMapping
    public ResponseEntity saveQuestions(@RequestBody Map<String, List<Answers>> map) {
        List<Answers> answers = map.get("answers");
        return testSoulService.saveQuestions(answers);
    }

    // 查看结果
    @GetMapping("/report/{reportId}")
    public ResponseEntity findResult(@PathVariable("reportId") Long reportId) {
        return testSoulService.findResult(reportId);
    }

}
